﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Paint.DisplayCoverage.TxColorPalette
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using System.Windows.Markup;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.Paint.DisplayCoverage;

public class TxColorPalette : TxWindow, IComponentConnector
{
  private bool _isColorDialogOpen;
  private Color _selectedColor;
  internal UiInternalControls.WPFControls.TxColorPaletteControl.TxColorPaletteControl colorPalette;
  private bool _contentLoaded;

  public Color SelectedColor
  {
    get => this._selectedColor;
    set => this._selectedColor = value;
  }

  public bool IsClosing { get; set; }

  public TxColorPalette() => this.InitializeComponent();

  private void colorPalette_ColorPicked(object sender, EventArgs e)
  {
    this.IsClosing = true;
    ((Window) this).Close();
    this.IsClosing = false;
    this._isColorDialogOpen = false;
  }

  private void colorPalette_ColorDialogOpening(object sender, EventArgs e)
  {
    this._isColorDialogOpen = true;
  }

  private void TxWindow_Activated(object sender, EventArgs e)
  {
    this.colorPalette.SelectedColor = this.SelectedColor;
  }

  private void TxWindow_Deactivated(object sender, EventArgs e)
  {
    if (this._isColorDialogOpen)
    {
      ((Window) this).Hide();
    }
    else
    {
      if (this.IsClosing)
        return;
      ((Window) this).Close();
    }
  }

  private void TxWindow_Closing(object sender, CancelEventArgs e)
  {
    this.SelectedColor = this.colorPalette.SelectedColor;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/paint/displaycoverage/cuipaintcolorpicker.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    if (connectionId != 1)
    {
      if (connectionId == 2)
      {
        this.colorPalette = (UiInternalControls.WPFControls.TxColorPaletteControl.TxColorPaletteControl) target;
        this.colorPalette.ColorPicked += new UiInternalControls.WPFControls.TxColorPaletteControl.TxColorPaletteControl.TxColorPaletteControl_ColorPickedEventHandler(this.colorPalette_ColorPicked);
        this.colorPalette.ColorDialogOpening += new UiInternalControls.WPFControls.TxColorPaletteControl.TxColorPaletteControl.TxColorPaletteControl_ColorDialogOpeningEventHandler(this.colorPalette_ColorDialogOpening);
      }
      else
        this._contentLoaded = true;
    }
    else
    {
      ((Window) target).Deactivated += new EventHandler(this.TxWindow_Deactivated);
      ((Window) target).Activated += new EventHandler(this.TxWindow_Activated);
      ((Window) target).Closing += new CancelEventHandler(this.TxWindow_Closing);
    }
  }
}
